<?php

use Adapter\EBookAdapter;
use Adapter\Kindle;
use Decorator\RenderInJson;
use Decorator\WebService;
use DependencyInjection\ArrayConfig;
use DependencyInjection\Connection;
use Facade\Computer;
use Factory\Factory;
use Instance\Instance;
use Observer\Event;
use Observer\Observer1;
use Observer\Observer2;
use Observer\Observer3;
use Observer\Observer4;

include "vendor/autoload.php";

spl_autoload_register('autoload');

function autoload($class)
{
    $class = str_replace('\\','/',$class);
    $file = realpath('./').'/'.$class.'.php';
    include $file;
}

// 工厂模式
// $factory = new Factory();
// $factory->create(1);

// 单例模式
// Instance::getInstance()->test();

// 适配器模式
// $ebook = new Kindle();
// $adapter = new EBookAdapter($ebook);
// $adapter->open();

// 装饰器模式
// $wrappable = new WebService(['test' => 1]);
// echo (new RenderInJson($wrappable))->renderData();

// 依赖注入模式
// $config = new ArrayConfig(['host' => '127.0.0.1']);
// $connection = new Connection($config);
// echo $connection->connect();

// 门面模式
// (new Computer())->run();

// 观察者模式
// $observer1 = new Observer1();
// $observer2 = new Observer2();
// $observer3 = new Observer3();
// $observer4 = new Observer4();
// $event = new Event();
// $event->attach($observer1);
// $event->attach($observer2);
// $event->attach($observer3);
// $event->attach($observer4);
// $event->notify();
